package com.mdd.admin.controller.goods;

import com.google.common.collect.Lists;
import com.mdd.admin.config.aop.Log;
import com.mdd.admin.service.goods.IGoodsService;
import com.mdd.admin.validate.common.PageParam;
import com.mdd.admin.validate.goods.GoodsBatchParam;
import com.mdd.admin.validate.goods.GoodsParam;
import com.mdd.admin.vo.goods.GoodsDetailVo;
import com.mdd.admin.vo.goods.GoodsListVo;
import com.mdd.admin.vo.goods.StatisticsGoodsVo;
import com.mdd.common.core.PageResult;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 服务管理
 */
@Api(tags = "服务管理")
@RestController
@RequestMapping("api/goods")
public class GoodsController {

    @Resource
    IGoodsService iGoodsService;

    /**
     * 服务列表
     *
     * @param pageParam 分页参数
     * @param params    搜索参数
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 分页列表")
    @GetMapping("/list")
    public PageResult<GoodsListVo> list(@Validated PageParam pageParam,
                                        @RequestParam Map<String, String> params) {
        return iGoodsService.list(pageParam, params);
    }

    /**
     * @return java.lang.Object
     * @Author slien
     * @Description 统计状态数据
     * @Date 10:17 2022/10/7
     * @Param [pageParam, params]
     **/
    @ApiOperation(value = "服务管理 - 统计状态数据")
    @GetMapping("/statistics")
    public StatisticsGoodsVo statistics(@RequestParam Map<String, String> params) {
        return iGoodsService.statistics(params);
    }

    /**
     * 服务详情
     *
     * @param id 主键ID
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务详情")
    @GetMapping("/detail")
    public GoodsDetailVo detail(@Validated @IDMust() @RequestParam("id") Long id) {
        return iGoodsService.detail(id);
    }

    /**
     * 服务新增
     *
     * @param goodsParam 参数
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务新增")
    @Log(title = "服务新增")
    @PostMapping("/add")
    public void add(@Validated(value = GoodsParam.create.class) @RequestBody GoodsParam goodsParam) {
        iGoodsService.add(goodsParam);
    }

    /**
     * 服务编辑
     *
     * @param goodsParam 参数
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务编辑")
    @Log(title = "服务编辑")
    @PostMapping("/edit")
    public void edit(@Validated(value = GoodsParam.update.class) @RequestBody GoodsParam goodsParam) {
        iGoodsService.edit(goodsParam);
    }

    /**
     * 服务删除
     *
     * @param goodsParam 参数
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务批量删除")
    @Log(title = "服务批量删除")
    @PostMapping("/del")
    public void del(@Validated @RequestBody GoodsBatchParam goodsParam) {
        iGoodsService.del(goodsParam.getIds());
    }

    @ApiOperation(value = "服务管理 - 服务删除")
    @Log(title = "服务删除")
    @GetMapping("/del")
    public void del(@Validated @RequestParam("id") Long id) {
        iGoodsService.del(Lists.newArrayList(id));
    }

    /**
     * 服务删除
     *
     * @param goodsParam 参数
     * @return Object
     */
    @ApiOperation(value = "服务管理 - 服务批量状态修改")
    @Log(title = "服务状态修改")
    @PostMapping("/status")
    public void updateStatus(@Validated @RequestBody GoodsBatchParam goodsParam) {
        iGoodsService.updateStatus(goodsParam.getIds(), goodsParam.getStatus());
    }

    @ApiOperation("服务管理 - 今日特价")
    @PostMapping("/addTodaySpecials")
    public void addTodaySpecials(@RequestBody Map<String, GoodsParam> map){
        iGoodsService.addTodaySpecials(map);
    }

    @ApiOperation("服务管理 - 今日特价")
    @PostMapping("/selectTodaySpecials")
    public Map<String, GoodsDetailVo> selectTodaySpecials(){
        return iGoodsService.selectTodaySpecials();
    }
}
